package com.spi.soconversion.orders.conversion;

import com.spi.soconversion.util.SOCConstants;
import com.spi.soconversion.util.SOCUtility;
import com.spi.soconversion.util.XMLAttributeConstants;
import com.spi.soconversion.util.XMLTagConstants;

public class InstallBaseAssociation {
	
	private final String createProgID=SOCConstants.EMPTY_STRING;
	private String createts;
	private String createUserID;
	private final String assocFromKey=SOCConstants.EMPTY_STRING;
	private final String assocToKey=SOCConstants.EMPTY_STRING;
	private final String installBaseAssocKey=SOCConstants.EMPTY_STRING;
	private final String lockID=SOCConstants.ZERO;
	private String warrantyStart;
	private String warrantyEnd;
	private WarrantyInstallBase wtyInstallBase=new WarrantyInstallBase();
	private boolean isExtendedWarrantyExists= false;
		
	public WarrantyInstallBase getWarrantyInstallBase() {
		return wtyInstallBase;
	}
	
	public String getAssocFromKey() {
		return assocFromKey;
	}
			
	public String getAssocToKey() {
		return assocToKey;
	}
	
	public void setWarrantyStart(String warrantyStart) {
		this.warrantyStart = warrantyStart;
	}
		
	public String getWarrantyStart() {
		return SOCUtility.checkNull(warrantyStart);
	}
	
	public void setWarrantyEnd(String warrantyEnd) {
		this.warrantyEnd = warrantyEnd;
	}
		
	public String getWarrantyEnd() {
		return SOCUtility.checkNull(warrantyEnd);
	}
	
	public String getLockID() {
		return lockID;
	}
	
	public String getInstallBaseKey() {
		return installBaseAssocKey;
	}
	
	public String getModifyProgID() {
		return getCreateProgID();
	}
	
	public String getModifyts() {
		return getCreatets();
	}
		
	public String getModifyUserID() {
		return getCreateUserID();
	}
	
	public String getCreateProgID() {
		return createProgID;
	}
	
	public void setCreatets(String createts) {
		this.createts = createts;
	}
		
	public String getCreatets() {
		return SOCUtility.checkNull(createts);
	}
	
	public void setCreateUserID(String createUserID) {
		this.createUserID = createUserID;
	}
	
	public String getCreateUserID() {
		this.createUserID = SOCUtility.checkNull(createUserID);
		if(createUserID.length()>40)
		{
			createUserID = createUserID.substring(0, 40);
		}
		return createUserID;
	}

	public void isExtendedWarranty(boolean isExtendedWarrantyExists)
	{
		this.isExtendedWarrantyExists= isExtendedWarrantyExists;
	}
	
	public boolean getIsExtendedWarranty()
	{
		return isExtendedWarrantyExists;
	}
	
	@Override
	public String toString()
	{
		StringBuilder sb = new StringBuilder();
		if(isExtendedWarrantyExists)
		{
			sb.append(XMLTagConstants.START_TAG_HBC_ASSOC_LIST);
			sb.append(SOCConstants.BLANK_STRING);
			
			sb.append(SOCConstants.NEW_LINE);
			sb.append(XMLTagConstants.START_TAG_HBC_IB_ASSOC);
			sb.append(SOCConstants.BLANK_STRING);
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.ASSOCIATE_FROM_KEY,getAssocFromKey()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.ASSOCIATE_TO_KEY, getAssocToKey()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.CREATE_PROG_ID, getCreateProgID()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.CREATE_TS, getCreatets()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.CREATE_USER_ID, getCreateUserID()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.INSTALL_BASE_ASSOC_KEY, getInstallBaseKey()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.LOCK_ID,getLockID()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.MODIFY_PROGID,getModifyProgID()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.MODIFY_TS, getModifyts()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.MODIFY_USER_ID, getModifyUserID()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.WARRANTY_START_DATE, getWarrantyStart()));
			
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCUtility.getAttribute(XMLAttributeConstants.WARRANTY_END_DATE, getWarrantyEnd()));
			
					
			sb.append(SOCConstants.BLANK_STRING);
			sb.append(SOCConstants.CLOSING_XML_TAG);
			sb.append(SOCConstants.NEW_LINE);
			sb.append(getWarrantyInstallBase().toString());
			sb.append(SOCConstants.NEW_LINE);
			sb.append(XMLTagConstants.END_TAG_HBC_IB_ASSOC);
			sb.append(SOCConstants.NEW_LINE);
			sb.append(XMLTagConstants.END_TAG_HBC_ASSOC_LIST);
		}
		return sb.toString();
	}
	
}
